package org.west.sky.frame.activiti.study.chapter15;

import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.west.sky.frame.activiti.study.util.ActivitiEngineUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * author: chz
 * date: 2025/4/15
 * description: Web Service 任务
 */
public class RunDemo15_2 extends ActivitiEngineUtil {

    public static void main(String[] args) {
        RunDemo15_2 runDemo15_2 = new RunDemo15_2();
        runDemo15_2.deploy();
    }

    private void deploy() {
        Properties properties = System.getProperties();
        properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        properties.put("mail.smtp.ssl.protocols", "TLSv1.2");
        loadActivitiConfigAndInitEngine("activiti.cfg.xml");
        ProcessDefinition processDefinition = deployByClassPathResource("processes/chapter15/Chapter15_2.bpmn20.xml");

        Map<String, Object> variables = new HashMap<>();
        variables.put("userName", "测试");
        variables.put("userMail", "1312817285@qq.com");
        variables.put("myMobileCode", "13588252151");

        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), variables);

        historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list().forEach(instance -> {
            System.out.println("====变量：" + instance.getVariableName() + "的值为：" + instance.getValue());
        });

        closeEngine();
    }
}
